#include #include "q2.h" static qele_type queue[q_MAX]; static int next_in = 0; static int next_out = 0; /* fetch an item from the queue */ qele_type q_get() { qele_type rval; /* first test to see if there is an item */ if (next_in == next_out) return EMPTY; qele_cpy(rval, queue[next_out++]); next_out &= q_WRAP; return rval; } /* put an item in the queue */ qele_type q_put(nval) qele_type nval; { qele_type rval; /* first check to see if the queue is full */ if (((next_in + 1) & q_WRAP) == next_out) return FULL; qele_cpy(queue[next_in++], nval); next_in &= q_WRAP; return NORMAL; } /* compute entries in queue */ int q_bsy() { return ((next_in + q_MAX) - next_out) & q_WRAP ; } /* compute free entries in queue */ int q_free() { return q_WRAP - (((next_in + q_MAX) - next_out) & q_WRAP); }